package com.alageek.study;

import com.alageek.study.game.Gamer;
import com.alageek.study.game.Memento;

/**
 * 备忘录模式
 */
public class Main {
    public static void main(String[] args) {
        Gamer gamer = new Gamer(100);
        Memento memento = gamer.createMemento();
        for (int i=0;i<100;i++){
            System.out.println("==== " + i);
            System.out.println("当前状态：" + gamer);
            gamer.bet();
            System.out.println("所持金钱为 " + gamer.getMoney() + " 元");
            if(gamer.getMoney()>memento.getMoney()){
                System.out.println("金钱增加，状态保存");
                memento = gamer.createMemento();
            }else {
                System.out.println("金钱减少，状态恢复");
                gamer.restoreMemento(memento);
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println();
        }
    }
}
